/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package experiments;

import java.io.File;
import java.util.Date;

/**
 *
 * @author ash
 */
public class Timestamp {
    public static void main(String[] a){
        
        
        //System.out.println();
        String name = "file.txt";
        System.out.println(getFinalName(name));
    }
    
        private static String getFinalName(String name){
        String finalName = name;
        
        File original = new File (name);
        if (original.exists()){
            
            int lastPeriod = name.lastIndexOf('.');
            finalName = name.substring(0,lastPeriod);
            String extension = name.substring(lastPeriod);
            String timestamp = new Long(new Date().getTime()).toString();
            return finalName + "_" + timestamp + extension;
        }
        return finalName;
    }
}
